﻿Public Class Form2

    Inherits System.Windows.Forms.Form

    Dim BiometriaConnection As String


    Dim result As Integer
    Dim handle_Renamed As Integer
    Dim deviceType As Integer
    Dim userID As Integer
    Private m_strError As String
    Private m_Serial As Integer
    Private m_UserID As String
    Private m_FingerIndex As Integer
    Private m_Template1 As Byte()
    Private m_Template1Size As Integer
    Private m_Template2 As Byte()
    Private m_Template2Size As Integer
    Private m_Memo As String
    '
    Private Const MAX_USERID_SIZE As Integer = 50
    Private Const MAX_TEMPLATE_SIZE As Integer = 1024
    Private Const MAX_MEMO_SIZE As Integer = 100
    '
    Private Const DATABASE_COL_SERIAL As Integer = 0
    Private Const DATABASE_COL_USERID As Integer = 1
    Private Const DATABASE_COL_FINGERINDEX As Integer = 2
    Private Const DATABASE_COL_TEMPLATE1 As Integer = 3
    Private Const DATABASE_COL_TEMPLATE2 As Integer = 4
    Private Const DATABASE_COL_MEMO As Integer = 5

    Private minuto As Integer = 0
    Private segundo As Integer = 0
    Private milisegundo As Integer = 0
    Private minutoM As Integer = 0
    Private segundoM As Integer = 0
    Private milisegundoM As Integer = 0

    Dim FalloalAbrir As Boolean = False
    Dim FalloEnvio As Boolean = False






    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub


    Sub IniciaLector()
        Try
            'ESTO ES EL SDK DEL LECTOR DE TARJETAS
            result = BS_InitSDK()
            userID = 0

            Dim deviceID As Object
            Dim IP As String = "192.168.254.117" 'Ip del BioEntry plus
            result = BS_OpenSocket(IP, 1471, handle_Renamed)


            If result <> 0 Then
                TextBox1.AppendText("No se pudo abrir el canal de comunicación " & IP & vbNewLine)
                FalloalAbrir = True
                Exit Sub
            End If

            result = BS_GetDeviceID(handle_Renamed, deviceID, deviceType)
            If result <> 0 Then
                TextBox1.AppendText("No se pudo obtener el ID del dispositivo" & vbNewLine)
                FalloalAbrir = True
                Exit Sub
            End If

            result = BS_SetDeviceID(handle_Renamed, deviceID, deviceType)

            If result <> 0 Then
                TextBox1.AppendText("No se pudo asignar el ID del dispositivo" & vbNewLine)
                FalloalAbrir = True
                Exit Sub
            End If

            FalloalAbrir = False
            TextBox1.AppendText("Se abrio correctamente el canal de comunicación" & vbNewLine)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        IniciaLector()
        Button1.Enabled = False
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        lectura()
    End Sub

    Sub lectura()

        Dim CardID As Integer
        Dim CustomID As Integer

        result = BS_ReadCardIDEx(handle_Renamed, CardID, CustomID)


        Label1.Enabled = True


        Label1.Text = "Leyendo tarjeta..."

        If result <> 0 Then
            Label1.Text = "El tiempo de espera expiró. Error : " & result
            Exit Sub
        End If


        TextBox2.Text = CardID.ToString

        MsgBox(CustomID.ToString)



    End Sub


End Class
